#ifndef _DevicesSPI_H_
#define _DevicesSPI_H_

#define SPI0_DMA_READ_LENGTH  (256)
#define SPI0_DMA_SEND_LENGTH  (256)
#define SPI1_DMA_READ_LENGTH  (256)
#define SPI1_DMA_SEND_LENGTH  (256 * 240)

#define SET_SPI1_NSS_HIGH() GPIO_BOP(GPIOB) = GPIO_PIN_12
#define SET_SPI1_NSS_LOW()  GPIO_BC(GPIOB) = GPIO_PIN_12



extern uint16_t g_SPI0ReadDMABuff[SPI0_DMA_READ_LENGTH + 4];
extern uint16_t g_SPI0SendDMABuff[SPI0_DMA_SEND_LENGTH + 4];
extern uint16_t g_SPI1ReadDMABuff[SPI1_DMA_READ_LENGTH + 4];
extern uint16_t g_SPI1SendDMABuff[SPI1_DMA_SEND_LENGTH + 4];



void vSPI1Init(void);
void vSPI1DMAInit(void);

uint8_t ucSPIWriteReadByte(uint32_t uiSpiPeriph, uint8_t ucByte);
int8_t cSPIWriteDatas(uint32_t uiSpiPeriph, uint8_t *pBuffer, int32_t iLength);
int8_t cSPIReadDatas(uint32_t uiSpiPeriph, uint8_t *pBuffer, int32_t iLength);

void vSPIxDMASetLenthStart(uint32_t dma_periph, dma_channel_enum channelx, uint32_t uiLength);
void vSPIxDMASetAddrAndLenthStart(uint32_t dma_periph, dma_channel_enum channelx, int8_t cDirection, uint32_t uiSourceAddress, uint32_t uiTargetAddress, uint32_t uiLength);
void vSPIxDMASendDatas(uint32_t uiUsartPeriph, uint8_t *pucDatas, int32_t iLength);


#endif
